#! /bin/sh
#### Run GBmod with CWP PostScript Graphics
#### Create Figure 6 in the GBmod paper

if test "$PSPREVIEWER" = ""
then
echo "Environment variable PSPREVIEWER not set" ; exit 1
fi

# model number
model=3


####  find the right directory
datadir=../datadir/

####  aux files
modelfile=${datadir}model${model}.data
modelpsfile=${datadir}model${model}.eps
rayendsfile=${datadir}rayend.data
rayfile=${datadir}ray.data
raypsfile=${datadir}ray.eps
wavefile=${datadir}wave.data
wavefilet=${datadir}wavet.data
wavepsfile=${datadir}wave.eps

nangle=150 nxz=201 fangle=-45 langle=45 nt=20

####   generate modelfile and modelpsfile
# ../Models/PSmodel${model}

####   shoot the rays 
triray <$modelfile >$rayendsfile \
        rayfile=$rayfile wavefile=$wavefile \
        nangle=$nangle fangle=$fangle langle=$langle \
        nxz=$nxz nt=$nt xs=1 zs=0.1 refseq=4,1 krecord=1\
	refseq=1,-1

####    transpose the wavefile
transp <$wavefile >$wavefilet n1=$nt n2=$nangle nbpe=8

####   plot the rays 
psgraph <$rayfile >$raypsfile \
        nplot=`cat outpar` n=$nxz hbox=3.0 wbox=6.0  \
        x1beg=0 x1end=1 x2beg=0 x2end=2 \
        label1="Depth (km)" label2="Distance (km)" \
        style=seismic linegray=1

####    plot the wavefronts
psgraph <$wavefilet >$wavepsfile  \
	linewidth=0 mark=8 marksize=2\
        nplot=$nt n=$nangle hbox=3.0 wbox=6.0\
        x1beg=0 x1end=1 x2beg=0 x2end=2 \
        label1="Depth (km)" label2="Distance (km)" \
        style=seismic 

####    display rays, model, and waves
$CWPROOT/bin/psmerge in=$modelpsfile in=$raypsfile in=$wavepsfile |
	$PSPREVIEWER &



exit 0
